package net.tplusplus.drools.speedtest.facts;

import net.tplusplus.drools.speedtest.bank.Account;
import net.tplusplus.rules.runner.rao.Fact;


public class UpdatingAccount implements Fact, Comparable<UpdatingAccount>
{
	private long accountNo;
	private Account account;
	
	public UpdatingAccount(long accountNo, Account account)
	{
		this.accountNo = accountNo;
		this.account = account;
	}

	public long getAccountNo()
	{
		return accountNo;
	}

	public void setAccountNo(long accountNo)
	{
		this.accountNo = accountNo;
	}

	public Account getAccount()
	{
		return account;
	}

	public void setAccount(Account account)
	{
		this.account = account;
	}
	
	/**
	 *  This method enables the Collections api to sort the 
	 *  UpdatingAccount by account no.
	 */	
	public int compareTo(UpdatingAccount updatingAccount)
	{
		if(getAccountNo()==updatingAccount.getAccountNo()) return 0;
		
		return (getAccountNo()>updatingAccount.getAccountNo()) ? 1 : -1;
	}
	
	/**
	 *  This method enables the comparison of UpdatingAccount objects
	 */	
	@Override
	public boolean equals(Object obj) 
	{
		if(obj==null || !(obj instanceof UpdatingAccount))
		{
			return false;
		}
		
		UpdatingAccount updatingAccount = (UpdatingAccount) obj;
		
		return (getAccountNo()==updatingAccount.getAccountNo());	
	}		
}
